package com.tech.tool.service.impl;

import com.tech.tool.dao.ApiInfoDao;
import com.tech.tool.dataobject.ApiInfo;
import com.tech.tool.exception.ToolException;
import com.tech.tool.repository.ApiRepository;
import com.tech.tool.service.ApiInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.NoSuchElementException;

@Service
public class ApiInfoServiceImpl implements ApiInfoService {

    @Autowired
    private ApiRepository repository;

    @Autowired
    private ApiInfoDao dao;

    @Override
    public Integer save(ApiInfo apiInfo) {
        return dao.insertByObject(apiInfo);
    }

    @Override
    public ApiInfo findOne(Integer apiId) {
        try {
            return repository.findById(apiId).get();
        } catch (NoSuchElementException e) {
            throw new ToolException(3, "11234");
        }
    }
}
